package com.example.provider.controller;

import java.util.List;

import com.example.common.base.BaseController;
import com.example.common.base.Paging;
import com.example.common.base.Result;
import com.example.common.model.UserBrowsingHistory;
import com.example.common.model.condition.UserBrowsingHistoryCondition;
import com.example.provider.service.UserBrowsingHistoryService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 用户的活动 浏览活动历史关系表  暂时不考虑广场文章的浏览历史Controller
 * 
 * @author 510
 * @version 1.0.0 2021-04-23
 */
@Api(tags = "用户的活动 浏览活动历史关系表  暂时不考虑广场文章的浏览历史服务")
@RestController
@RequestMapping("/userBrowsingHistory")
public class UserBrowsingHistoryController extends BaseController {
    @Autowired
    private UserBrowsingHistoryService userBrowsingHistoryService;

    @ApiOperation(value = "根据查询参数分页查询用户的活动 浏览活动历史关系表  暂时不考虑广场文章的浏览历史列表")
    @ApiImplicitParam(name = "condition", value = "用户的活动 浏览活动历史关系表  暂时不考虑广场文章的浏览历史查询条件", required = true, dataType = "UserBrowsingHistoryCondition", paramType = "body")
    @PostMapping("/list")
    public Paging<UserBrowsingHistory> list(@RequestBody UserBrowsingHistoryCondition condition) {
        IPage<UserBrowsingHistory> page = userBrowsingHistoryService.findUserBrowsingHistoryByCondition(condition);
        return Paging.buildPaging(page);
    }

    @ApiOperation(value = "根据主键ID查询用户的活动 浏览活动历史关系表  暂时不考虑广场文章的浏览历史信息")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true)
    @GetMapping(value = "/get/{id}")
    public Result<UserBrowsingHistory> get(@PathVariable Integer id) {
        if (id == null) {
            return Result.failed("请选择需要查询的数据！");
        }
        UserBrowsingHistory userBrowsingHistory = userBrowsingHistoryService.getUserBrowsingHistoryById(id);
        return Result.ok(userBrowsingHistory);
    }

    @ApiOperation(value = "新增用户的活动 浏览活动历史关系表  暂时不考虑广场文章的浏览历史信息")
    @ApiImplicitParam(name = "userBrowsingHistory", value = "用户的活动 浏览活动历史关系表  暂时不考虑广场文章的浏览历史", required = true, dataType = "UserBrowsingHistory", paramType = "body")
    @PostMapping("/add")
    public Result<?> add(@RequestBody UserBrowsingHistory userBrowsingHistory) {
        boolean bool = userBrowsingHistoryService.addUserBrowsingHistory(userBrowsingHistory);
        if (bool) {
            return Result.ok(userBrowsingHistory);
        }
        return Result.failed();
    }

    @ApiOperation(value = "修改用户的活动 浏览活动历史关系表  暂时不考虑广场文章的浏览历史信息")
    @ApiImplicitParam(name = "userBrowsingHistory", value = "用户的活动 浏览活动历史关系表  暂时不考虑广场文章的浏览历史", required = true, dataType = "UserBrowsingHistory", paramType = "body")
    @PutMapping(value = "/update")
    public Result<?> update(@RequestBody UserBrowsingHistory userBrowsingHistory) {
        Integer id = userBrowsingHistory.getId();
        if (id == null) {
            return Result.failed("请选择需要修改的数据！");
        }
        boolean bool = userBrowsingHistoryService.updateUserBrowsingHistory(userBrowsingHistory);
        return Result.okOrFailed(bool);
    }

    @ApiOperation(value = "根据主键ID删除用户的活动 浏览活动历史关系表  暂时不考虑广场文章的浏览历史")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true)
    @DeleteMapping(value = "/delete/{id}")
    public Result<?> delete(@PathVariable Integer id) {
        if (id == null) {
            return Result.failed("请选择需要删除的数据！");
        }
        boolean bool = userBrowsingHistoryService.deleteUserBrowsingHistoryById(id);
        return Result.okOrFailed(bool);
    }

    @ApiOperation(value = "根据主键ID列表批量删除用户的活动 浏览活动历史关系表  暂时不考虑广场文章的浏览历史")
    @ApiImplicitParam(name = "idList", value = "主键ID列表", required = true, allowMultiple = true, paramType = "body")
    @DeleteMapping("/deleteList")
    public Result<?> deleteList(@RequestBody List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)) {
            return Result.failed("请选择需要删除的数据！");
        }
        boolean bool = userBrowsingHistoryService.deleteUserBrowsingHistoryByIds(idList);
        return Result.okOrFailed(bool);
    }
}